var arr = [
    {name:"可口可乐",price:2.3,sales:1000,grade:9.5},
    {name:"百事可乐",price:3,sales:900,grade:9.8},
    {name:"非常可乐",price:1.5,sales:750,grade:8.5},
    {name:"健力宝",price:5,sales:100,grade:9.6},
]
//设计一个函数，实现可以根据不同属性进行排序
function paixu(prop,orderBy){
    //1.设计了一个用于产生比较器函数的函数
    function factory(prop){
        return function(a,b){
            if(a[prop]>b[prop]){
                return 1;
            }else{
                return -1;
            }
        }
    }
    //2.根据需求产生比较器函数
    var comparator = factory(prop);
    //3. 比较
    arr.sort(comparator);
}
paixu("grade",1);
console.log(arr);
